package com.lindroid.gesturelock;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class SettingActivity extends AppCompatActivity {
    private GestureLockView lockView;
    private List<Integer> passList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        lockView = (GestureLockView) findViewById(R.id.gestureLockView);
        lockView.setOnDrawFinishedListener(new GestureLockView.OnDrawFinishedListener() {
            @Override
            public boolean OnDrawFinished(List<Integer> passList) {
                if (passList.size() < 3) {
                    Toast.makeText(SettingActivity.this, "密码不能少于3", Toast.LENGTH_SHORT).show();
                    return false;
                } else {
                    SettingActivity.this.passList = passList;
                    return true;
                }
            }
        });
    }

    public void resetClick(View view) {
        lockView.resetPoints();
    }

    public void saveClick(View view) {
        if (passList != null) {
            StringBuilder sb = new StringBuilder();
            for (Integer i : passList) {
                sb.append(i);
            }
            Toast.makeText(this, "保存完成", Toast.LENGTH_SHORT).show();
            Log.e("Tag", "点的顺序：" + sb.toString());
            SharedPreferences sp = SettingActivity.this.getSharedPreferences("Password", SettingActivity.this.MODE_PRIVATE);
            SharedPreferences.Editor editor = sp.edit();
            editor.putString("Password", sb.toString());
            editor.commit();
        }
    }
}
